package com.luoqiz.designPatterns.factory.factory;

import com.luoqiz.designPatterns.util.XMLUtil;

public class MainClient {
	public static void main(String[] args) {
		// 测试1
		test1();
		// 基于开闭原则和里氏代换原则的测试2
		test2();
	}

	private static void test2() {
		// 从外部文件读取需要实例化的对象类，通过反射实现实例化
		String className = XMLUtil.getLoggerFactoryClass();
		try {
			Class<?> c = Class.forName(className);
			LoggerFactory loggerFactory = (LoggerFactory) c.newInstance();
			Logger logger = loggerFactory.createLogger();
			logger.writeLog();
		} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
			e.printStackTrace();
		}

	}

	static void test1() {
		LoggerFactory loggerFacotry = new FileLoggerFactory();
		Logger logger = loggerFacotry.createLogger("ftp://192.168.0.12/1.log");
		logger.writeLog();
	}
}
